home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / dsp / 56000tar.z / 56000tar / 56000 / speech / durbin1.asm < prev    next >
Assembly Source File  |  1991-11-26  |  6KB  |  156 lines

  1. ;
  2. ; This program originally available on the Motorola DSP bulletin board.
  3. ; It is provided under a DISCLAMER OF WARRANTY available from
  4. ; Motorola DSP Operation, 6501 Wm. Cannon Drive W., Austin, Tx., 78735.
  5. ; Durbin Solution for PARCOR (LPC) Coefficients
  6. ; Last Update 3 June 87   Version 1.2
  7. ;
  8. ;       Implements the Durbin LPC algorithm.
  9. ;
  10.         opt     cex
  11.         page    132,66,3,3
  12. ;
  13. ;       i/o file definitions
  14. ;
  15. datain   equ    $ffff
  16. dataout  equ    $fffe
  17. nk       equ    10              ;10th order LPC analysis
  18.  
  19.         org     x:0             ;I/O values in X: memory
  20. r       ds      nk+1            ;autocorrelation coefficients
  21. k       ds      nk              ;reflection coefficients
  22.  
  23.         org     y:0             ;temporary values in Y: memory
  24. acoeffs dc      $7fffff         ;define a[0] = 1.0
  25.         ds      nk              ;LPC filter coefficients
  26. anew    dc      $7fffff         ;define anew[0] = 1.0
  27.         ds      nk              ;updated LPC filter coefficients
  28. alpha   ds      1               ;Durbin alpha
  29. error   ds      1               ;Durbin error
  30.  
  31.         org     p:$100
  32. ;
  33. ;       find out how many frames to process
  34. ;
  35.         movep   y:datain,n0
  36.         do      n0,endframe
  37.  
  38. ;
  39. ;       load the autocorrelations from an external file
  40. ;
  41.         move    #r,r0           ;load autocorrelation
  42.         do      #nk+1,loadr     ;get nk+1 autocorrelation values
  43.         movep   y:datain,a      ;get next autocorrelation value
  44.         move    a,x:(r0)+       ;and save it in the r array
  45. ;
  46. ;       The following registers correspond to the C variables:
  47. ;
  48. ;       r0 - r[i]               r4 - acoeffs[i]
  49. ;       r1 - k[i-1]             r5 - acoeffs[j-1]
  50. ;       r2 - r[i-j+1]           r6 - acoeffs[i-j+1]
  51. ;       r3 - anew[j-1]          r7 - loop counter
  52. ;
  53. ;       Approximate analysis times:
  54. ;
  55. ;            8th  order: 63.5  uS
  56. ;            10th order: 85.6  uS
  57. ;            16th order: 165.7 uS
  58. ;
  59. ;       Initialization
  60. ;
  61. loadr   move    #r,r0                   ;r(0) points to r[0]
  62.         move    #k,r1                   ;r(1) points to k[0]
  63. ;
  64. ;       Begin Durbin Algorithm
  65. ;
  66.         move    x:(r0)+,x0              ;get r[0]
  67.         move    x:(r0)+,a               ;get r[1], r(0) points to r[i]
  68.         abs     a          a,b          ;get abs(r[1]), copy r[1] to b
  69.         eor     x0,b  #acoeffs+1,r4     ;N = sign bit, r(4) points to a[i]
  70.         and     #$fe,ccr                ;make quotient positive
  71.         rep     #24                     ;set up for 24-bit quotient
  72.         div     x0,a                    ;get abs(r[1])/r[0]
  73.         jmi     L1                      ;check sign bit N
  74.         neg     a                       ;negate quotient if needed
  75. L1      move    a0,a                    ;move -r[1]/r[0] to A
  76.         clr     b   a,x:(r1)+  a,y0     ;k[0] = -r[1]/r[0], copy k[0] to y0
  77.         move    #$800000,b1             ;b = 1.0, r(1) points to k[i-1]
  78.         macr    -y0,y0,b  #2,r7         ;b=1.0-(k[0]*k[0]),loop counter=2
  79.         move    b,x1  a,y:(r4)+         ;x1 = 1.0-(k[0] * k[0]), a[1] = k[0]
  80.         mpyr    x1,x0,a   #2,n7         ;a1 = r[0] * (1.0 - (k[0] * k[0]))
  81.         move    a,y1                    ;alpha = r[0] * (1.0 - k[0] * k[0]))
  82.         move    #-2,n5                   ;initialize n(5) 
  83. ;
  84. ;       outer do loop  (note: alpha = y1)
  85. ;
  86.         do      #nk-1,L6                ;do outer do loop (nk-1) times
  87.         move    r0,r2                   ;r(2) points to r[i]
  88.         move    #acoeffs,r5             ;r(5) points to a[0]
  89.         move    (r0)+                   ;r(0) points to next r[i]
  90.         clr     a x:(r2)-,x0 y:(r5)+,y0 ;error = 0, preload 1st operand set
  91. ;
  92. ;       inner do loop #1  (note: r7 = i)
  93. ;
  94.         do      r7,L2                         ;do inner do loop #1 (i) times
  95.         mac     x0,y0,a x:(r2)-,x0 y:(r5)+,y0 ;error += a[j-1] * r[i-j+1]
  96. ;
  97. ;       back to outer do loop  (note: error = a)
  98. ;
  99. L2      abs     a          a,b          ;get abs(error), copy error to b
  100.         eor     y1,b       #2,n6        ;N = sign bit, y1 = alpha
  101.         and     #$fe,ccr                ;make quotient positive
  102.         rep     #24                     ;set up for 24-bit quotient
  103.         div     y1,a                    ;get abs(error)/alpha
  104.         jmi     L3                      ;check sign bit N
  105.         neg     a                       ;negate quotient if needed
  106. L3      move    a0,a                    ;move k[i-1] = -(error/alpha) to a
  107.         clr b   a,x0    a,y:(r4)+       ;put k[i-1] in x0, a[i] = k[i-1]
  108.         move    a,x:(r1)+  y:(r7)-,a    ;k[i-1] = -(error/alpha), dec r(7)
  109.         move    #$800000,b1             ;b = 1.0
  110.         macr    -x0,x0,b    r4,r6       ;b = 1.0 - (k[i-1] * k[i-1])
  111.         move    b,x1                    ;r(6) points to a[i+1]
  112.         mpyr    x1,y1,b   (r6)-n6       ;b = alpha * (1.0-(k[i-1]*k[I-1]))
  113.         move    b,y1                    ;save alpha=alpha*(1-k[i-1]*k[i-1])
  114.         move    #acoeffs+1,r5           ;r(5) points to a[j-1]
  115.         move    #anew+1,r3              ;r(3) points to anew[j-1]
  116.         move    y:(r6)-,y0              ;y0 = a[i-j+1], x0 = k[i-1]
  117.         move    y:(r5)+,a               ;a = a[j-1]
  118. ;
  119. ;       inner do loop #2  (note: r7 = (i-1))
  120. ;
  121.         do      r7,L4                   ;do inner do loop #2 (i-1) times
  122.         macr    x0,y0,a  y:(r6)-,y0     ;get anew[j-1], y0 = next a[i-j+1]
  123.         move    a,y:(r3)+               ;anew[j-1]=a[j-1]+k[i-1]*a[i-j+1]
  124.         move    y:(r5)+,a               ;a = a[j-1]
  125. ;
  126. ;       end of inner do loop #2
  127. ;
  128. ;       inner do loop #3  (note: r7 = (i-1))
  129. ;
  130. L4      move    x:(r3)-,x0 y:(r5)+n5,y0 ;dummy reads to dec r(3) and r(5)
  131.         do      r7,L5                   ;do inner do loop #3 (i-1) times
  132.         move    y:(r3)-,a               ;get anew[j-1]
  133.         move    a,y:(r5)-               ;a[j-1] = anew[j-1]
  134. ;
  135. ;       end of inner do loop #3
  136. ;
  137. ;       end of outer do loop
  138. ;
  139. ;       end of analysis
  140. ;
  141. ;       output reflection coefficients to an external file
  142. ;
  143. L5      move    (r7)+n7                 ;update loop counter
  144. L6      move    #k,r1                   ;point to reflection coeffs.
  145.         do      #nk,endsend             ;output nk k values
  146.         move    x:(r1)+,x0              ;get next k value
  147.         move    x0,y:dataout            ;output next K coefficient value
  148. endsend
  149.         nop
  150. endframe
  151.         nop
  152.         end
  153.  
  154.